<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ChapterCommunityRequest.aspx.cs" errorPage="~/Error.aspx" Inherits="SecurityLinkUp.ChapterCommunityRequest" Title="Community / Chapter Request" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" runat="server">
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>

<script type="text/javascript">      
      var Map = null;      
      Sys.Application.add_load(GetMap);
      
      function GetMap()
      {
        Map = new VEMap('Map'); 
        Map.SetDashboardSize(VEDashboardSize.Tiny); 
        Map.LoadMap(new VELatLong(0,0), 0, 'r', false,VEMapMode.Mode2D, false);
        //Map.Clear();
        // resize is required in this instance to force the map to size correctly on the page
        Map.Resize(400,400);
      } 
      
      function RefreshMap()
      {
        //GetMap();
      }
  
      function FindLocation (loc)
      {
        try
        {
            var loc = document.getElementById("ctl00_ContentPlaceHolder_NewRequestContainer_NewChapterTab_ChapterGeoArea").value;
        
            if (loc != "")
            {
                GetMap();
                var resultslayer = new VEShapeLayer();
                Map.AddShapeLayer(resultslayer);
                Map.Find('', loc, VEFindType.Businesses, resultslayer, 0, 5, true, true, false, true, ProcessResults);
             }
        }
        catch (e)
        {
            alert(e.message);
        }
      }              
                
      
      function ProcessResults(layer, findResults, places, hasmore)
      {
            for (resultID in places)
            {                
                var latitude = places[resultID].LatLong.Latitude;
                var longitude = places[resultID].LatLong.Longitude;                
                AddPushpin(resultID, latitude, longitude, places[resultID].Name, GenerateDescription(latitude, longitude));
            }
      }
      
      function AddPushpin(pinId, latitude, longitude, title, details)
      {
        var vell = new VELatLong(latitude, longitude);
        var pp = new VEPushpin(pinId, vell, null , title, details, 'pushpin');
        Map.AddPushpin(pp);       
      } 
      
      function GenerateDescription(Lat, Long)
      {
           var link = '<a href=\"javascript:SetLatLongValues(\'';           
           link +=Lat;
           link +='\', \'';
           link +=Long;
           link +='\')\"> Set this point as location </a>';
           return link;
      }
      
      function SetLatLongValues(Lat, Long)
      {
         document.getElementById("ctl00_ContentPlaceHolder_NewRequestContainer_NewChapterTab_GeoLat").value = Lat;
         document.getElementById("ctl00_ContentPlaceHolder_NewRequestContainer_NewChapterTab_GeoLong").value = Long;
         document.getElementById("ctl00_ContentPlaceHolder_NewRequestContainer_NewChapterTab_ChapterLocationStatusImg").src = "/images/check.png"; 
      }

</script>


    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <cc1:TabContainer ID="NewRequestContainer" runat="server" ActiveTabIndex="1" Width="850px" Height="500px">
        <cc1:TabPanel ID="NewCommunityTab" runat="server" HeaderText="New Community" >
            <ContentTemplate>
            <table cellpadding="5">
            <tr>
                <td valign="top">
                    Community Name</td>
                <td style="width: 235px" valign="top">
                    <asp:TextBox ID="CommunityName" runat="server" Width="199px"></asp:TextBox></td>
            </tr>
            <tr>
                <td valign="top">
                    Description<br />
                    <small>[Describe what this community is/does]</small></td>
                <td style="width: 235px" valign="top">
                    <asp:TextBox ID="CommunityDescription" runat="server" Rows="4" TextMode="MultiLine" Width="200px"></asp:TextBox></td>
            </tr>
            <tr>
                <td valign="top">
                    Reason/justification for request<br />
                    <small>[Give the admins a reason why to approve this request]</small></td>
                <td style="width: 235px" valign="top">
                    <asp:TextBox ID="CommunityReason" runat="server" Rows="4" TextMode="MultiLine" Width="199px"></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Label ID="CommunityErrorMessage" CssClass="ErrorMessage" runat="server"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <asp:Button ID="SaveCommunityBtn" runat="server" Text="Save" OnClick="SaveCommunityBtn_Click" /></td>
            </tr>
        </table>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel ID="NewChapterTab" runat="server" HeaderText="New Chapter">
            <ContentTemplate>
                <table cellpadding="5">
            <tr>
                <td valign="top">
                    Chapter Name</td>
                <td style="width: 236px" valign="top">
                    <asp:TextBox ID="ChapterName" runat="server" Width="195px"></asp:TextBox></td>
                <td rowspan="8">
                <div id='Map' style="width: 400px; height: 400px; position:relative;"></div>
                    <asp:HiddenField ID="GeoLat" runat="server" />
                    <asp:HiddenField ID="GeoLong" runat="server" />
                </td>
            </tr>
                    <tr>
                        <td valign="top">
                            Parent Community</td>
                        <td style="width: 236px" valign="top">
                            <asp:DropDownList ID="ParentCommunity" runat="server" Width="202px">
                            </asp:DropDownList>
                            <cc1:ListSearchExtender ID="ListSearchExtender1" runat="server" TargetControlID="ParentCommunity" PromptPosition="Bottom" Enabled="True">
                            </cc1:ListSearchExtender>
                            <br /><br />
                        </td>
                    </tr>
            <tr>
                <td valign="top">
                    Description<br />
                    <small>[Describe what this community is/does]</small>
                </td>
                <td style="width: 235px" valign="top">
                    <asp:TextBox ID="ChapterDescritpion" runat="server" Rows="4" TextMode="MultiLine" Width="200px"></asp:TextBox></td>
            </tr>
            <tr>
                <td valign="top">
                    Reason/justification for request<br />
                    <small>[Give the admins a reason why to approve this request]</small></td>
                <td style="width: 235px" valign="top">
                    <asp:TextBox ID="ChapterReason" runat="server" Rows="4" TextMode="MultiLine" Width="199px"></asp:TextBox></td>
            </tr>
            <tr>
                <td valign="top">
                    Geographic Area<br />
                    <small>[Geographic region where this chapter operates - optional]</td>
                <td style="width: 235px" valign="top">
                    <asp:TextBox ID="ChapterGeoArea" runat="server" Width="159px"></asp:TextBox>
                    <input type="button" id="FindChapterBtn" value="Find" onclick="FindLocation()" />
                </td>
            </tr>
            <tr>
                <td valign="top">
                    Location Encoded
                    </td>
                <td style="width: 235px" valign="top">
                    <asp:Image ID="ChapterLocationStatusImg" ImageUrl="~/Images/cross.png" runat="server" ImageAlign="Top" /> 
                    <div><small>[Hover over map pins to set location]</small></div>
                    </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Label ID="ChapterErrorMessage" CssClass="ErrorMessage" runat="server"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <asp:Button ID="SaveChapterBtn" runat="server" Text="Save" OnClick="SaveChapterBtn_Click" /></td>
            </tr>
        </table>
            </ContentTemplate>
        </cc1:TabPanel>
    </cc1:TabContainer>
    </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>
